﻿IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetDirectoryEntry]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetDirectoryEntry]
GO

CREATE PROCEDURE [dbo].[GetDirectoryEntry]
	@UserRoles TNVarCharSet READONLY,
	@PathOrId nvarchar(MAX)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @Id bigint
	
	EXEC GetDirectoryEntryId @PathOrId, 0, @Id = @Id OUTPUT
	
	IF @Id IS NULL RETURN 1
	
	DECLARE @Name nvarchar(256)
	DECLARE @ParentId bigint
	DECLARE @CreatedOn datetime
	DECLARE @UpdatedOn datetime
	DECLARE @Type int
	
	SELECT 
		@ParentId = ParentId, 
		@Name = Name, 
		@CreatedOn = CreatedOn, 
		@UpdatedOn = UpdatedOn, 
		@Type = [Type]
	FROM DirectoryEntry
	WHERE Id = @Id AND dbo.HasPermission(@UserRoles, @Id, 1) = 1

	IF @Name IS NULL RETURN 1

/*--SpecificSelects--*/	
	
	RETURN 0
END
GO